// pages/index/RankingList/artist/artist.js
const api = require('../../../../wxapi/config.js')
const util = require('../../../../utils/util.js')
Page({
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		return {
			title: '影视行业大数据',
			path: '/pages/index/RankingList/artist/artist'
		}
	},
	/**
	 * 页面的初始数据
	 */
	data: {
		isloading: true,
		skeleton: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    touxiang: 'https://cdn.xtde.cn/wxapp/xtde/touxiang.jpg',
    artistList: [],
    tag: 0,
    closingTime: '',
		type: 0,
    active: 0
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.getData(this.data.type, this.data.tag)
    this.setData({
      closingTime: util.formatClosingTime(new Date())
    })
	},

  onChangeNav(event) {
		this.setData({
			type: event.detail.index,
      isloading: true,
      artistList: [],
			tag: 0,
			active: 0
		})
		this.getData(this.data.type, this.data.tag)
  },

  /**
	 * navTab切换
	 */
  onChangeBomtNav(event) {
    this.setData({
      tag: event.detail.index,
      isloading: true,
      artistList: [],
    })
		this.getData(this.data.type, this.data.tag)
  },

  getData(type, val) {
    const urlMap = { 0: "getArtistList", 1: "getArtistWorkInfluenceList" }
    api[`${urlMap[type]}`]({ tag: val }).then((res) => {
      if (res.data.length !== 0) {
        this.setData({
          artistList: res.data,
          isloading: false
        })
      } else {
        this.setData({
          artistList: [],
          isloading: false
        })
      }
    })		
  }
})